﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using pLib;
using System.Collections.Generic;

namespace UnitTestMain
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            int number1 = 30;
            int number2 = 30;
            bool valueChanged = number1 != number2;

            Assert.AreEqual(valueChanged, false);

            int num1 = 2;
            int num2 = 1024;
            Assert.AreEqual(0, num1 & num2);
        }

        [TestMethod]
        public void TestXMLToObject()
        {
            XMLToObject x = new XMLToObject();
            string xml = @"<xml>
        <mengde>100</mengde>
        <type>2</type>
        <foo>bar</foo>
        </xml>";
            Dictionary<string, string> d = x.XMLMapDictionary(xml);
            Assert.AreEqual(d["mengde"], "100");
            Assert.AreEqual(d["type"], "2");
            Assert.AreEqual(d["foo"], "bar");
        }

        [TestMethod]
        public void TestXMLToObjectWithAttribute()
        {
            XMLToObject x = new XMLToObject();
            string xml = "<database><def number=\"1\" name=\"one\"/><def number=\"2\" name=\"two\"/></database>";
            Dictionary<string,string> d =
            x.XMLMapDictionaryAttribute(xml);

            Assert.AreEqual(d["1"], "one");
            Assert.AreEqual(d["2"], "two");
        }

        [TestMethod]
        public void TestXMLMapDictionaryWithValueAttribute()
        {
            string s = "<data><resource key=\"123\">foo</resource><resource key=\"456\">bar</resource><resource key=\"789\">bar</resource></data>";
            XMLToObject x = new XMLToObject();

            SortedDictionary<string, string> d =
                x.XMLMapDictionaryWithValueAttribute(s);

            Assert.AreEqual(d["123"], "foo");
            Assert.AreEqual(d["456"], "bar");
            Assert.AreEqual(d["789"], "bar");
        }
        [TestMethod]
        public void TestMyDatabase()
        {
            MyDatabase myDatabase = new MyDatabase();

            Assert.AreEqual(myDatabase.GetConnectionStringFromApp(), "Persist Security Info=False;Integrated Security=true;Initial Catalog=DatabaseName;server=ServerName;Pooling=false");
        }
    }
}
